clear all
set mem 100m
set more off
cd "C:\data\NationalAssembly\NA Leadership\data"
use DELEGATEquery_clean

sort pci_id

merge pci_id using province_data.dta
drop upper_leadership


gen upper_leadership =1 if leadership1==5 | leadership1==6
replace upper_leadership=0 if upper_leadership==.


gen ln_gdpcap06=ln( gdpcap_2006)
gen electiondistrict2=electiondistrict*10

/*Assessing whether Government Ministers Were Favored*/
gen seats=0
replace seats=1 if candidates_seat>1.8

ttest power_total if centralnom==1 & politburo==0, by(government)
ttest candidates_seat if centralnom==1 & politburo==0, by(government)

set more off

xi3: firthlogit government upper_l centralnom politburo
outreg2 using appendix1, e(all) replace
xi3: firthlogit seats centralnom politburo government upper_l male minority party age degree religion incumbencyterms south trans_rev ln_gdpcap06 
outreg2 using appendix1, e(all) 
/*xi3: firthlogit  seats politburo government upper_l male minority party age degree religion incumbencyterms south trans_rev ln_gdpcap06 i.prov_id*/
/*outreg2 using appendix1, e(all) */
xi3: firthlogit  seats politburo government upper_l male minority party age degree religion incumbencyterms south trans_rev ln_gdpcap06 if centralnom==1 
outreg2 using appendix1, e(all) 
xi3: reg  power_total centralnom politburo government upper_l male minority party age degree religion incumbencyterms south trans_rev ln_gdpcap06
outreg2 using appendix1, e(all)
xi3: reg  power_total centralnom politburo government upper_l male minority party age degree religion incumbencyterms south trans_rev ln_gdpcap06 i.prov_id
outreg2 using appendix1, e(all)
xi3: reg  power_total politburo government upper_l male minority party age degree religion incumbencyterms south trans_rev ln_gdpcap06 if centralnom==1 
outreg2 using appendix1, e(all) excel






/*Create Variable for upper leadership, which includes NA Standing Committee and Committee Deputy Chairmen*/


/*VNA Leadership*/
set more off
xi3: firthlogit upper_leadership percentage
outreg2 using upper_leadership, e(all) replace
xi3: firthlogit upper_leadership percentage age male minority religion degree south
outreg2 using upper_leadership, e(all) 
xi3: firthlogit upper_leadership percentage age male minority religion degree south incumbencyterms centralnom
outreg2 using upper_leadership, e(all)
xi3: firthlogit upper_leadership percentage age male minority religion degree south incumbencyterms centralnom ln_gdpcap06 trans_rev
outreg2 using upper_leadership, e(all)
xi3: firthlogit upper_leadership percentage age male minority religion degree south  incumbencyterms ln_gdpcap06 trans_rev if centralnom==0
outreg2 using upper_leadership, e(all) 
xi3: firthlogit upper_leadership percentage age male minority religion degree south  incumbencyterms ln_gdpcap06 trans_rev if centralnom==1
outreg2 using upper_leadership, e(all) 
xi3: firthlogit upper_leadership percentage age male minority religion degree incumbencyterms centralnom  i.prov_id
outreg2 using upper_leadership, e(all) excel





/*Fulltime*/
set more off
xi3: firthlogit fulltime percentage
outreg2 using fulltime, e(all) replace
xi3: firthlogit fulltime percentage age male minority religion degree south
outreg2 using fulltime, e(all) 
xi3: firthlogit fulltime percentage age male minority religion degree south incumbencyterms centralnom
outreg2 using fulltime, e(all)
xi3: firthlogit fulltime percentage age male minority religion degree south incumbencyterms centralnom ln_gdpcap06 trans_rev
outreg2 using fulltime, e(all)
xi3: firthlogit fulltime percentage age male minority religion degree south  incumbencyterms ln_gdpcap06 trans_rev if centralnom==0
outreg2 using fulltime, e(all) 
xi3: firthlogit fulltime percentage age male minority religion degree south  incumbencyterms ln_gdpcap06 trans_rev if centralnom==1
outreg2 using fulltime, e(all) 
xi3: firthlogit fulltime percentage age male minority religion degree incumbencyterms centralnom  i.prov_id
outreg2 using fulltime, e(all) excel




/*Government*/
set more off
xi3: firthlogit government percentage
outreg2 using government, e(all) replace
xi3: firthlogit government percentage incumbent_govt
outreg2 using government, e(all) 
xi3: firthlogit government  percentage age male minority religion degree south incumbent_govt
outreg2 using government, e(all) 
xi3: firthlogit government percentage age male minority religion degree south incumbencyterms centralnom incumbent_govt
outreg2 using government, e(all)
xi3: firthlogit government percentage age male minority religion degree south incumbencyterms centralnom ln_gdpcap06 trans_rev incumbent_govt
outreg2 using government, e(all)
xi3: firthlogit government percentage age male minority religion degree south  incumbencyterms ln_gdpcap06 trans_rev if centralnom==0
outreg2 using government, e(all) 
xi3: firthlogit government percentage age male minority religion degree south  incumbencyterms ln_gdpcap06 trans_rev if centralnom==1
outreg2 using government, e(all) 
xi3: firthlogit government percentage age male minority religion degree   incumbencyterms centralnom  incumbent_govt i.prov_id
outreg2 using government, e(all) excel


/*Electoral District FE*/
set more off
xi3: firthlogit upper_leadership percentage age male minority religion degree incumbencyterms centralnom  i.electiondistrict2
outreg2 using upper_leadership, e(all) excel
xi3: firthlogit fulltime percentage age male minority religion degree incumbencyterms centralnom  i.electiondistrict2
outreg2 using fulltime, e(all) excel
xi3: firthlogit government percentage age male minority religion degree   incumbencyterms centralnom  incumbent_govt i.electiondistrict2
outreg2 using government, e(all) excel

/***********************************************************************************************************************************/

ttest degree, by(upper_leadership)
ttest degree, by(fulltime)
ttest degree, by(centralnom)


drop if result==0
drop _merge
sort delegate_id
merge delegate_id using delegate_speeches


gen crit_per= (criticize_total/question_count)*100
gen ln_critper=ln(crit_per)
replace ln_critper=0 if ln_critper==.

drop _merge
sort delegate_id
merge delegate_id using debate

replace debate_spee=0 if debate_spee==.

set more off
xi3: nbreg  question_count upper_ age male degree south party incumbencyterms i.career, cluster(pci_id)
outreg2 using loyalty, e(all) replace
xi3: nbreg criticize_total upper_  age male degree south party incumbencyterms  i.career  , cluster(pci_id)
outreg2 using loyalty, e(all)
xi3: nbreg  question_count upper_  age male degree south party incumbencyterms pop_2006 trans_rev secondary i.career, cluster(pci_id)
outreg2 using loyalty, e(all)
xi3: nbreg criticize_total upper_   age male degree south party incumbencyterms pop_2006 trans_rev secondary i.career, cluster(pci_id)
outreg2 using loyalty, e(all)
xi3: nbreg  question_count upper_ fulltime centralnom  age male degree south party incumbencyterms pop_2006 trans_rev secondary i.career, cluster(pci_id)
outreg2 using loyalty, e(all)
xi3: nbreg criticize_total upper_ fulltime centralnom  age male degree south party incumbencyterms pop_2006 trans_rev secondary i.career, cluster(pci_id)
outreg2 using loyalty, e(all) excel



